﻿using System;
using Token.Piker.Common;
using Token.Piker.Core;

namespace Token.Piker.Web
{
    public partial class Single : PikerBasePage
    {
        public static int startIndex=0;
        public static int picNum=0; //用户上传图片总数
        //相册拥有者信息
        public static string UserName = "";
        public static string UserPic = "";
        //评论者信息（在线用户）
        public static string pUserName = "";
        public static string pUserPic = "";
        public static string UID;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                UID = (Request.QueryString["UID"] == null || Request.QueryString["UID"] == "") ? "0" : Request.QueryString["UID"];
                int UserID = Session[GlobalConstants.PIKER_USER_ID] == null ? 0 : Int32.Parse(Session[GlobalConstants.PIKER_USER_ID].ToString().Trim());//当前在线用户
                //object PID = Request.QueryString["PID"];
                if (UID != null && UID.ToString() != "")
                {
                    //相册拥有者信息
                    Token.Piker.Model.User user = GetUser(UID.ToString());
                    UserName = user.UserName;
                    UserPic = user.UserPic;
                    //评论者信息（在线用户）
                    Token.Piker.Model.User puser = GetUser(UserID.ToString());
                    pUserName = puser.UserName;
                    pUserPic = puser.UserPic;
                    //绑定图片数据
                    Token.Piker.BLL.PhotoBLL singleBll = new Token.Piker.BLL.PhotoBLL();
                    string whereStr="";
                    if (UserID != 0)
                    {
                        whereStr = string.Format(" UserID= {0} ", UID.ToString());
                    }
                    else
                    {
                        whereStr = "";
                    }
                    picNum = singleBll.GetRecordCount(whereStr);
                    Single_pic.DataSource = picNum >= 12 ? singleBll.GetListByPage(string.Format(" UserID= {0} ", UID.ToString()), "ID",1, 12) : singleBll.GetListByPage(string.Format(" UserID= {0} ", UID), "ID", 1, picNum);
                }
                else
                {
                    Single_pic.DataSource = null;
                }
                    Single_pic.DataBind();
            }
            else
            {
            }
            
        }

        public string GetUserName(string UID)
        {
            Token.Piker.Model.User pikerUser = new Token.Piker.Model.User();
            if (UID != "0")
            {
                //绑定用户名
                Token.Piker.BLL.UserBLL Userbll = new Token.Piker.BLL.UserBLL();                
                pikerUser = Userbll.GetModel(Int32.Parse(UID.ToString()));
            }
            else
            {
                pikerUser = new Token.Piker.Model.User();
            }
            return pikerUser == null ? "游客" : pikerUser.UserName;
        }

        public Token.Piker.Model.User GetUser(string UID)
        {
            if (UID == "0")
            {
                Token.Piker.Model.User pUser = new Token.Piker.Model.User();
                pUser.UserName = "游客";
                pUser.UserPic = "../Images/youke.jpg";
                return pUser;
            }
            //绑定用户名
            Token.Piker.BLL.UserBLL Userbll = new Token.Piker.BLL.UserBLL();
            Token.Piker.Model.User pikerUser = new Token.Piker.Model.User();
            pikerUser = Userbll.GetModel(Int32.Parse(UID.ToString()));
            if (pikerUser == null || pikerUser.UserName == null)
            {
                pikerUser = new Token.Piker.Model.User();
                pikerUser.UserName = "游客";
                pikerUser.UserPic = "../Images/youke.jpg";
            }
            return pikerUser;
        }
    }
}